package edu.pku.sei.transformation.editor.controller.policies;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.CreateRequest;

import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.transformation.editor.controller.commands.CommandFactory;
import edu.pku.sei.transformation.editor.model.variable.ObjectVariable;

public class GraphicalDomainXYLayoutPolicy extends CommonXYLayoutPolicy {
	@Override
	protected Command getAddCommand(Request request) {
		if (request instanceof CreateRequest) {
			Rectangle constraint = (Rectangle) getConstraintFor((CreateRequest)request);
			MetaNode node = (MetaNode) ((CreateRequest)request).getNewObject();
			if (node == null)
				return null;
			MetaNode father = (MetaNode) getHost().getModel();
			if (node.getModelElement() instanceof ObjectVariable) {
				return CommandFactory.getCreateCommand(node, father, constraint);
			} else {
				return null;
			}
		} else {
			return null;
		}
	}
}
